home *** CD-ROM | disk | FTP | other *** search
/ Aminet 33 / Aminet 33 - October 1999.iso / Aminet / dev / cross / ava-0.2.5.lha / ava-0.2.5 / src / Symbol.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-03-23  |  3.0 KB  |  93 lines

  1. /* Symbol.h, Uros Platise */
  2.  
  3. #ifndef __Symbol
  4. #define __Symbol
  5.  
  6. #include "Lexer.h"
  7. #include "Segment.h"
  8. #include <string>
  9. #include <map>
  10.  
  11. #define SYM_MAX_PARAM    32
  12.  
  13. struct TSymbolRec{
  14.   enum TAttr{Internal=0,Extern=1,Public=2,Virtual=4};
  15.   TAttr attr;            /* attributes */
  16.   int tbl_offset;        /* attribute error chk. */
  17.   string macro;            /* macro string */
  18.   int noArgs;            /* number of parameters */
  19.   int segNo;            /* symbol belongs to segment */
  20.   string ref;            /* file reference and */
  21.   int refCnt;            /* reference count */
  22.   bool label;            /* if symbol is label */
  23.   bool internal;        /* protected symbols, for internal use */
  24.   PSegTable segP;        /* link to translation table: segP is
  25.                                    also used to declare owner - since each file
  26.                    has its own translation table */  
  27.   TSymbolRec():attr(0),noArgs(0),segNo(SEGNUMBER_UNDEFINED),
  28.                refCnt(0),label(false),internal(false){}
  29. };
  30.  
  31. class TSymbol{
  32.   enum TOperation{Define=1,OK=2,Common=3,Error1,Error2};
  33.   typedef map< string, TSymbolRec, less<string> >::const_iterator TsymCI;
  34.   typedef map< string, TSymbolRec, less<string> >::iterator TsymI;
  35.   
  36.   map< string, TSymbolRec, less<string> > sym;
  37.   static TOperation ErrorTable[16];
  38.   
  39.   bool HaltOnMacro;
  40.   bool undefEqZero;
  41.  
  42.   /* Parameter Stack Operations */
  43.   char param_stack[SYM_MAX_PARAM][LX_LINEBUF];
  44.   int psi;    /* Parameter's Stack Index */
  45.   
  46.   void clearps(){psi=0;}
  47.   void addps(char *s);
  48.   void replace(char *s);
  49.   void replaceParameters(char* s);  
  50.   
  51. private:
  52.   void GiveUndefinedSymVal(bool zero=false){undefEqZero=zero;}
  53.   int  Replace2Zero();
  54.   void storeSym(TSymbolRec* tmpRec, const string& macroName);
  55.   void parseFlags(TSymbolRec* pRec, int terminator_type);
  56.   void parseMacro(TSymbolRec* pRec);
  57.   void reparseMacro(TSymbolRec* pRec);
  58.   void parseReference(TSymbolRec* pRec);
  59.   TOperation test(TSymbolRec* pRec, const string& macroName);
  60.   
  61. public:
  62.   TSymbol():HaltOnMacro(false),undefEqZero(false){}
  63.   ~TSymbol(){}  
  64.   
  65.   bool addMacro();    /* returns true, if symbol is written as "__XXX" */
  66.   void addMacro(const char* macroName, const char* label=NULL,
  67.                 TSymbolRec::TAttr macro_attr=TSymbolRec::Internal);                       
  68.   int addLabel();    /* return 1, if label was added ... otherwise 0 */
  69.   bool ifexpr();    /* return true if expression is true */
  70.   bool ifdef();        /* return true if symbol is already in database */
  71.   string* findMacro(const string& macroName);
  72.   void undefine();
  73.   void undefine(const string& macroName);
  74.   
  75.   long noRefs(int segNo); /* number of references for segment segNo */
  76.   
  77.   void addInternalLabel(const char* macroName, const char* label=NULL);
  78.   void modifyValue(const char* macroName, const char* macroString);  
  79.   int replaceWithMacro(); /* test if str is macro -> replace it and return 1 
  80.                    otherwise 0 */
  81.   void haltOnMacro(bool confirm=true){HaltOnMacro=confirm;}
  82.   
  83.   void saveSymbols();
  84.   void loadSymbols(); 
  85.   void loadNonPublicSymbols();
  86.   void updatePublic();
  87. };
  88.  
  89. extern TSymbol symbol;
  90.  
  91. #endif
  92.  
  93.